﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace ZhangZhao.WebAPI
{
   [System.ComponentModel.Description("被UploadPhoto.ashx取代")]
    public partial class UserGatherThirdPhotoEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string s = Output.Fail;

            try
            {
                string Command = HttpUtility.HtmlEncode(HttpContext.Current.Request[Parameter.Command]);

                string UserName = HttpContext.Current.Request[Parameter.UserName];
                string ThirdUserName = HttpContext.Current.Request["ThirdUserName"];
                string ThirdPhotoThumb = HttpContext.Current.Request[Parameter.ThirdPhotoThumb];
                string ThirdPhotoLarge = HttpContext.Current.Request[Parameter.ThirdPhotoLarge];
                string IsLike = HttpContext.Current.Request[Parameter.IsLike];
                string ShortDescription = HttpContext.Current.Request[Parameter.ShortDescription];
                int UserGatherThirdPhotoId = 0;
                int.TryParse(HttpContext.Current.Request[Parameter.UserGatherThirdPhotoId], out UserGatherThirdPhotoId);

                if (!string.IsNullOrWhiteSpace(Command))
                {
                    ZhangZhao.BLL.H_UserGatherThirdPhoto bll = new ZhangZhao.BLL.H_UserGatherThirdPhoto();

                    if (Command.Equals(CommandParameterValue.Add, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //添加收藏
                        bll.Add(new ZhangZhao.Model.H_UserGatherThirdPhoto()
                        {
                            CreatedTime = DateTime.Now,
                            IsLike = IsLike,
                            ShortDescription = ShortDescription,
                            ThirdPhotoLarge = ThirdPhotoLarge,
                            ThirdPhotoThumb = ThirdPhotoThumb,
                            ThirdUserName = ThirdUserName,
                            UserName = UserName,
                            ViewCount = 1
                        });

                        s = Output.Success;
                    }

                    if (Command.Equals(CommandParameterValue.Delete, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //删除收藏
                        if (UserGatherThirdPhotoId > 0)
                        {
                            bll.Delete(UserGatherThirdPhotoId);
                            s = Output.Success;
                        }
                    }

                    if (Command.Equals(CommandParameterValue.Update, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //修改收藏
                        if (UserGatherThirdPhotoId > 0)
                        {
                            bll.Update(new ZhangZhao.Model.H_UserGatherThirdPhoto()
                            {
                                CreatedTime = DateTime.Now,
                                IsLike = IsLike,
                                ShortDescription = ShortDescription,
                                ThirdPhotoLarge = ThirdPhotoLarge,
                                ThirdPhotoThumb = ThirdPhotoThumb,
                                ThirdUserName = ThirdUserName,
                                UserName = UserName,
                                ViewCount = 1,
                                Id = UserGatherThirdPhotoId
                            });
                            s = Output.Success;
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                s = Output.Exception + ":" + ex.Message;
            }

            Response.Clear();
            Response.Write(s);
            Response.End();
        }
    }
}